<div class="card">
  <div class="card-header">
    <div class="card-title flex-container">
      <strong class="float-start" id="title_orgname">$org['orgname']</strong>
      <!--{if $_G['adminid']==1}-->
      <a href="{MOD_URL}&op=export&orgid=$orgid" class="btn btn-outline-primary float-end" title="{lang export_excl}" target="_blank">{lang export_user}</a> 
      <!--{/if}-->
    </div>
  </div>
  <div class="card-body">
    <div class="row mb-3">
      <label class="col-sm-2" for="orgname">{lang orgname}</label>
      <div class="col-sm-10">
        <input type="text" class="form-control" id="orgname" data-oldname="$org[orgname]" value="$org[orgname]" placeholder="{lang orgname_placeholder}" onchange="set_org_orgname('$org['orgid']',this)">
      </div>
    </div>
    <div class="row mb-3">
      <label class="col-sm-2">Logo</label>
      <div class="col-sm-10">
        <ul class="group-head">
          <li class="head-portrait">$org['avatar']</li>
          <li class="head-file me-2">
              <button type="button" class="btn btn-outline-primary" style="margin-top: 5px;cursor: pointer;"><input type="checkbox" class="headinput-checkbox" name="arr[aid]" value="$value[aid]" checked="checked"  onchange="set_org_logo('$org['orgid']',this.value)">重置</button>
          </li>
          <li class="head-file">
              <button type="button" class="btn btn-outline-primary" style="margin-top: 5px;cursor: pointer;"><input type="file" style=" cursor: pointer;" onclick="upload_bgphoto(this,true)"> {lang change}</button>
          </li>
        </ul>
      </div>
    </div>
    <div class="row mb-3">
        <label class="col-sm-2" for="arrdesc">{lang org_description}</label>
        <div class="col-sm-10">
          <textarea class="form-control" id="arrdesc" name="arr[desc]" rows="1" placeholder="{lang org_description_placeholder}" onchange="set_org_desc('$org['orgid']',this.value)">$org[desc]</textarea>
        </div>
    </div>
    <!--{if $folder_available}-->
    <!--原共享目录设置：diron,此处暂时用来控制应用内是否开启共享目录，如网盘群组开关不开启，表示网盘内不显示该目录-->
    <div class="row mb-3">
      <label class="col-sm-2">{lang shared_directory_set}</label>
        <div class="col-sm-10">
        <div class="form-check form-check-inline">
          <input class="form-check-input" type="radio" id="folder_available_1" name="fid" value="1" <!--{if $org[diron]>0}-->checked="checked"<!--{/if}--> onclick="folder_available(1,'$orgid');"  />
          <label class="form-check-label" for="folder_available_1">{lang enable}</label>
        </div>
        <div class="form-check form-check-inline">
          <input class="form-check-input" type="radio" id="folder_available_0" name="fid"  value="0" <!--{if $org[diron]<1}-->checked="checked"<!--{/if}--> onclick="folder_available(0,'$orgid');" />
          <label class="form-check-label" for="folder_available_0">{lang no_enable}</label>
        </div>
        <!--{if $org['forgid']<1}-->
        <small class="form-text">{lang detail_org_explorerapp_enable}</small>
        <!--{else}-->
        <small class="form-text">{lang detail_org_enable}</small>
        <!--{/if}-->
        </div>
    </div>
    <!--{/if}-->
    <!--{if $_G['adminid']==1 || $topmoderator}-->
    <div class="row mb-3">
    <label for="maxspacesize" class="col-sm-2">{lang org_space_assign}</label>
      <div class="col-sm-10">
        <div class="input-group mb-3">
        <input type="text" class="form-control" id="maxspacesize" name="maxspacesize" value="$org['maxspacesize']" onchange="folder_maxspacesize(this,'$orgid')">
        <span class="input-group-text">M</span>
        </div>
        <ul class="form-text">
        <li>{lang org_space_assign_tip}:<span class="text-danger">{eval echo ($allowallotspace == 0) ? lang('no_limit'):formatsize($allowallotspace);}</span>
        </li>{lang org_space_assign_tips}
        </ul>
      </div>
    </div>
    <!--{/if}-->
    <div class="row mb-3">
      <label class="col-sm-2"><!--{if $org[forgid]>0}-->{lang space_use_department}<!--{else}-->{lang space_use_org}<!--{/if}--></label>
      <div class="col-sm-10">
        <div class="progress" style="height: 1rem;">
          <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: {eval echo round(100*($org['usesize']/($org['maxspacesize']?$org['maxspacesize']*1024*1024:($org['usesize']+1024*1024*1024))))}%;min-width: 100px;" aria-valuenow="{eval echo round(100*($org['usesize']/($org['maxspacesize']?$org['maxspacesize']*1024*1024:($org['usesize']+1024*1024*1024))))}" aria-valuemin="0" aria-valuemax="100">{eval echo formatsize($org['usesize'])}/{eval if($org['maxallotspacesize'] == -1) echo formatsize($org['usesize']);else echo ($org['maxallotspacesize'] == 0)?lang('no_limit'):formatsize($org['maxallotspacesize'])}</div>
        </div>
        <ul class="form-text">
          {lang space_use_org_tips}
        </ul>
      </div>
    </div>
    <div class="row mb-3">
    <label class="col-sm-2">{lang position_management}</label>
    <div class="col-sm-10 clearfix jobs">
      <!--{loop $jobs $value}-->
      <div id="job_$value[jobid]" orgid="$value['orgid']" class="job-item-edit float-start pe-2">
        <button onclick="job_show_editor('$value[jobid]','$value['orgid']', this)" class="btn btn-outline-secondary job-name">$value[name]</button>
        <div class="edit hide" style="min-width:250px">
          <div class="input-group">
            <div class="job-edit-control float-start">
              <input type="text" class="form-control" value="$value[name]" onkeyup="if(event.keyCode==13){job_save('$value[jobid]','$value['orgid']');return false;}">
            </div>
            <button class="btn btn-outline-secondary" onclick="job_save('$value[jobid]','$value['orgid']')" data-loading-text="{lang save}" type="button">{lang save}</button>
            <button class="btn btn-outline-danger" onclick="job_del('$value[jobid]','$value['orgid']')" type="button">{lang delete} </button>
          </div>
        </div>
      </div>
      <!--{/loop}-->
      <div class="new-job float-start" style="padding:0 10px;">
        <a href="javascript:;" onclick="job_show_add_editor('$orgid',this)" class="btn btn-outline-primary"> {lang add_position} </a>
        <div class="new-job-control hide input-group" style="min-width:250px">
          <div class="float-start">
            <input type="text" class="new-job-text form-control" onkeyup="if(event.keyCode==13){job_add('$orgid');return false;}" placeholder="{lang position_name}">
          </div>
          <button class="btn btn-outline-secondary" data-loading-text="{lang add}" onclick="job_add('$orgid')" type="button">{lang add} </button>
          <button class="btn btn-outline-secondary" onclick="job_cancel_add_editor('$orgid')" type="button">{lang cancel}</button>
        </div>
      </div>
    </div>

    </div>
    <div class="row mb-3">
    <label class="col-sm-2"><!--{if $org['forgid']<1}-->{lang organization}<!--{else}-->{lang department}<!--{/if}--> {lang administrator}</label>
    <div class="col-sm-10">
      <ul id="moderators_container_$orgid" class="moderators-container list-unstyled clearfix">
        <!--{if $pmoderator}-->
        <li class="moderators-acceptor float-start" orgid="$orgid" style="">
          <div class="avatar-cover"></div>
          <div class="user-item-avatar">
            <div class="avatar-face">
              <img src="avatar.php?uid=0&size=middle">
            </div>
          </div>
        </li>
        <!--{/if}-->
        <!--{loop $moderators $value}-->
        <li class="user-item float-start" uid="$value['uid']">
          <!--{if $pmoderator}-->
          <div class="delete" onclick="moderator_del('$value[id]','$orgid',this);"><i style="color:#d2322d;font-size:16px" class="mdi mdi-delete">&nbsp;</i></div>
          <!--{/if}-->
          <div class="avatar-cover"></div>
          <div class="user-item-avatar">
            <div class="avatar-face">
              {eval echo avatar_block($value['uid']);}
            </div>
          </div>
          <p class="text-center" style="height:20px;margin:5px 0;line-height:25px;overflow:hidden;"> $value[username]</p>
        </li>
        <!--{/loop}-->

      </ul>

      <ul class="form-text " style="line-height:2">
        {lang detail_org_administrator}
      </ul>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript">
	jQuery(document).ready(function(e) {
		jQuery('textarea').TextAreaExpander(37);
	});
    function set_submit(form) {
        jQuery.post('$_G[siteurl]'+'{MOD_URL}&op=ajax&do=orginfo',jQuery(form).serialize(), function (data) {
            if (data['success']) {
				showmessage('{lang org_update_success}','success',3000,1);
				setTimeout(location.reload(),30000);
            }else if(data['error']){
				showmessage(data['error'],'danger',3000,1);
            }
        },'json').fail(function (jqXHR, textStatus, errorThrown) {
            showmessage('操作失败，请稍后再试: ' + textStatus, 'error', 3000, 1);
        });
        
        return false;
    }
	jQuery(document).on('click','.moderators-acceptor',function(){
		var ids=[];
		jQuery('.moderators-container .user-item').each(function(){
			ids.push(jQuery(this).attr('uid'));
		});
		showWindow('moderators','index.php?mod=system&op=selorguser&stype=2&multiple=1&template=1&callback=callback_moderators&token=$orgid&ids='+ids.join(','),'get',0,'',1)
		
	});
    jQuery(document).on('click','.headinput-checkbox',function(){
        if(jQuery(this).prop("checked")){
            jQuery(this).closest('.head-portrait').siblings('.head-portrait').find('.headinput-checkbox').prop('checked',false).parents('.head-checkbox').removeClass('hover');
            jQuery(this).parents('.head-portrait').find('.head-checkbox').addClass('hover');
        }else{
            jQuery(this).parents('.head-portrait').find('.head-checkbox').removeClass('hover');
        }

    });
	function upload_bgphoto(obj,fact) {
        'use strict';
        jQuery(obj).fileupload({
            url: '{MOD_URL}&op=ajax&do=upload',
            dataType: 'json',
            autoUpload: true,
            maxFileSize: 2000000,// 2 MB
            maxChunkSize: 2000000,//2M
            acceptFileTypes: new RegExp("\.([jpe?g|gif|png])$", 'i'),
            sequentialUploads: true,
            add: function (e, data) {
                data.context = jQuery('<div id="main"></div>');
                if (jQuery('#main div:first').length > 0) jQuery('#main div:first').before(data.context);
                else {
                    jQuery('#main').append(data.context);
                }
                data.process().done(function () {
                    data.submit();
                });
            },
            progress: function (e, data) {
                var index = 0; //data.index,
                var node = jQuery(data.context.children()[index]);
                var progress = parseInt(data.loaded / data.total * 100, 10);
                node.find('.progress-bar').css(
                        'width',
                        progress + '%'
                );
            },
            done: function (e, data) {

                jQuery.each(data.result.files, function (index, file) {
                    if (file.error) {
                        data.context.find('.progress').replaceWith('<span class="text-danger">' + file.error + '</span>');
                    } else {
                    	if(fact){
                    		var imgsexists = false;
                    		jQuery('.headinput-checkbox').each(function(){
                    			var oldaid = jQuery(this).val();
								if(oldaid == file.data.aid){
									jQuery(this).prop('checked',true);
									imgsexists = true;
									showmessage('{lang org_img_uploaded_tip}','success',3000,1);
									return false;
								}
							})
							if(!imgsexists){
								/*jQuery.post('{MOD_URL}&op=ajax&do=getdefaultpic',{aid:file.data.aid},function(data){
									if(data['success']){
										//jQuery('.head-checkbox').removeClass('hover').find('.headinput-checkbox').prop('checked',false);*/
										var html ='<li class="head-portrait">'+'<img src="'+file.data.img+'"><div class="head-checkbox hover">'+
												'<div class="checkbox-custom"> <input type="checkbox" class="headinput-checkbox" name="arr[aid]" value="'+file.data.aid+'" checked="checked" onchange="set_org_logo(\'$org['orgid']\',this.value)" />'+
												' </div> </div> ';
										jQuery('.head-portrait').replaceWith(html);
										set_org_logo('$orgid',file.data.aid);
								/*	}
								},'json')*/
							}
                    	}else{
                    		data.context.data('aid', file.data.aid).find('img').attr('src', file.data.img).end().find('.progress-container').hide();
                            var html = '<div class="col-sm-7 setting-img"><img class="img-rounded" src="'+file.data.img+'"><p class="upload-click">{lang clicktoupload}</p> <input type="file" id="exampleInputFile" onclick="upload_bgphoto(this)" name="files[]"></div>';				
							set_org_bgphoto('$org['orgid']',file.data.aid);
                            jQuery('.setting-img').replaceWith(html);

                    	}
                        
                    }
                });
            }
        })
    };
 
 
</script>